package com.product.android.business.login;

import java.io.Serializable;

import org.json.JSONObject;

import com.common.android.utils.JSONUtils;
import com.product.android.business.ApplicationVariable;
import com.product.android.commonInterface.contact.OapUser;
import com.product.android.utils.TimeUtils;

public class BindUser implements Serializable {
    public static final int DATA_COMPLETE = 0;
    private static final long serialVersionUID = 1L;
    private boolean tag;
    public static final int PARENT = 3;
    public static final int STUDENT = 2;
    public static final int STAFF = 1;
    public static final int UNIT_TYPE_COM = 0; // 单位
    public static final int UNIT_TYPE_EDU = 1; // 教育
    protected int id;
    protected long uid; // 身份编号（11位整型） 还没有写入数据库
    protected long uap_uid; // 此身份绑定用户通行证为null或0代表未绑定用户通行证（11位整型）
    protected String nickname; // 用户昵称（40位字符）
    protected String joindate; // 入职时间（12位字符）
    protected String telephone; // 计费电话（20位字符）
    protected String signature; // 个性签名（64位字符）
    protected long updatetime; // 记录最后更新时间，时间戳（11位整型）
    protected long friend_updatetime;
    protected int isactive; // /标识用户账户是否已激活，1为激活，0未激活 （1位整型）
    protected int sysavatar; // 默认为1，0标识为自定义头像，系统默认头像图片id（4位整型）
    protected String username; // 用户姓名（40位字符）
    protected int type; // 人员分类 1=职员 2=学生 3=家长（5位整型）
    protected String workid; // 工号 可选项 教职工时显示 15位字符）
    protected String duty; // 主要职务（32位字符）
    protected String mobilephone; // 常用手机（20位字符）
    protected String email; // 电子邮件（32位字符）
    protected int unitid; // 所在单位编号（11位整型）
    protected String unitname; // 所在单位名称
    protected String unitshortname; // 所在单位简称
    protected String studentid; // 学号 可选项 学生时显示 15位字符）
    protected int deporcassid; // 部门或班级编号

    // 扩展
    protected String gender; // 性别可选，为null不修改 0=保密 1=男 2=女（5位整型）
    protected String birthday; // 生日 （10位字符）
    protected String blood; // 血型 （10位字符）
    protected String site; // 个人主页 （255位字符）
    protected String description; // 个人说明 （255位字符）
    protected String fax; // 传真 （20位字符）
    protected String addr; // 联系地址 （255位字符）
    protected String postcode; // 邮编 （10位字符）
    // 增加资料
    protected String unitcode; // 单位代码
    protected int isadmin; // getadmin=1时返回此值 =1表示是管理员 =0表示不是管理员（4位整型）
    protected int unittype; // 单位类型 =0普通单位，=1学校（5位整型）
    protected int isgetall = 1; // 是否取完所有资料 1 表示没有取完，0表示取完
    protected int isgetextinfo; // 是否取过扩展资料 1 表示取过，0表示没有取过

    private int receivegroupmsg = 0; // 备用

    public BindUser() {
        birthday = "";
        gender = "";
    }

    public BindUser(OapUser oapUser) {
        try {
            this.uid = oapUser.getUid();
            this.uap_uid = oapUser.getUap_uid();
            this.nickname = oapUser.getNickname();
            this.joindate = oapUser.getJoindate();
            this.telephone = oapUser.getTelephone();
            this.signature = oapUser.getSignature();
            this.updatetime = Long.parseLong(oapUser.getUpdatetime());
            this.isactive = oapUser.getIsactive();
            this.sysavatar = oapUser.getSysavatar();
            this.username = oapUser.getUserName();
            this.type = oapUser.getType();
            this.workid = oapUser.getWorkid();
            this.duty = oapUser.getDuty();
            this.mobilephone = oapUser.getMobilehone();
            this.email = oapUser.getEmail();
            this.unitid = oapUser.getUnitid();
            this.unitname = oapUser.getUnitName();
            // this.unitshortname = oapUser.getu;
            this.studentid = oapUser.getStudentid();
            this.gender = oapUser.getGender() + "";
            this.birthday = oapUser.getBirthday();
        } catch (NumberFormatException e) {
            e.printStackTrace();
        }
    }

    public BindUser(JSONObject json) {
        // Log.v("UserInfo","json: "+json.toString());
        this.uid = JSONUtils.getLong(json, "uid");
        this.uap_uid = JSONUtils.getLong(json, "uap_uid");
        this.nickname = JSONUtils.getString(json, "nickname");
        this.joindate = JSONUtils.getString(json, "joindate");
        this.telephone = JSONUtils.getString(json, "telephone");
        this.signature = JSONUtils.getFilterString(json, "signature");
        this.updatetime = JSONUtils.getInt(json, "updatetime");
        this.isactive = JSONUtils.getInt(json, "isactive");
        this.sysavatar = JSONUtils.getInt(json, "sysavatar");
        this.username = JSONUtils.getString(json, "username");
        this.type = JSONUtils.getInt(json, "type");
        this.workid = JSONUtils.getString(json, "workid");
        this.duty = JSONUtils.getString(json, "duty");
        this.mobilephone = JSONUtils.getString(json, "mobilephone");
        this.email = JSONUtils.getString(json, "email");
        this.unitid = JSONUtils.getInt(json, "unitid");
        this.unitname = JSONUtils.getString(json, "unitname");
        this.unitshortname = JSONUtils.getString(json, "unitshortname");
        this.studentid = JSONUtils.getString(json, "studentid");
        this.gender = JSONUtils.getString(json, "gender");
        this.birthday = JSONUtils.getString(json, "birthday");
    }

    public void initUserBybindlistJson(JSONObject json) {
        this.uid = JSONUtils.getLong(json, "uid");
        this.username = JSONUtils.getString(json, "username");
        this.type = JSONUtils.getInt(json, "type");
        this.workid = JSONUtils.getString(json, "workid");
        this.studentid = JSONUtils.getString(json, "studentid");
        this.duty = JSONUtils.getString(json, "duty");
        this.mobilephone = JSONUtils.getString(json, "mobilephone");
        this.email = JSONUtils.getString(json, "email");
        this.sysavatar = JSONUtils.getInt(json, "sysavatar");
        this.unitid = JSONUtils.getInt(json, "unitid");
        this.unitname = JSONUtils.getString(json, "unitname");
        this.unittype = JSONUtils.getInt(json, "unittype");
    }

    @Override
    public String toString() {
        StringBuffer strbuf = new StringBuffer();

        strbuf.append(" uid=" + uid);
        strbuf.append(" uap_uid=" + uap_uid);
        strbuf.append(" nickname=" + nickname);
        strbuf.append(" joindate=" + joindate);
        strbuf.append(" telephone=" + telephone);
        strbuf.append(" signature=" + signature);
        strbuf.append(" updatetime=" + updatetime);
        strbuf.append(" isactive=" + isactive);
        strbuf.append(" sysavatar=" + sysavatar);
        strbuf.append(" username=" + username);
        strbuf.append(" type=" + type);
        strbuf.append(" workid=" + workid);
        strbuf.append(" duty=" + duty);
        strbuf.append(" mobilephone=" + mobilephone);
        strbuf.append(" email=" + email);
        strbuf.append(" unitid=" + unitid);
        strbuf.append(" unitname=" + unitname);
        strbuf.append(" studentid=" + studentid);

        strbuf.append(" gender=" + gender);
        strbuf.append(" birthday=" + birthday);
        strbuf.append(" blood=" + blood);
        strbuf.append(" site=" + site);
        strbuf.append(" description=" + description);
        strbuf.append(" fax=" + fax);
        strbuf.append(" addr=" + addr);
        strbuf.append(" postcode=" + postcode);
        strbuf.append(" friend_updatetime=" + friend_updatetime);

        strbuf.append(" unittype=" + unittype);
        strbuf.append(" isgetall=" + isgetall);
        strbuf.append(" isgetextinfo=" + isgetextinfo);
        return strbuf.toString();
    }

    public void setId(int id) {
        this.id = id;
    }

    public int getId() {
        return id;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public String getWorkid() {
        return workid;
    }

    public void setWorkid(String workid) {
        this.workid = workid;
    }

    public String getStudentid() {
        return studentid;
    }

    public void setStudentid(String studentid) {
        this.studentid = studentid;
    }

    public String getDuty() {
        return duty;
    }

    public void setDuty(String duty) {
        this.duty = duty;
    }

    public String getMobilephone() {
        return mobilephone;
    }

    public String getUnitshortname() {
        return unitshortname;
    }

    public void setUnitshortname(String unitshortname) {
        this.unitshortname = unitshortname;
    }

    public String getUnitcode() {
        return unitcode;
    }

    public void setUnitcode(String unitcode) {
        this.unitcode = unitcode;
    }

    public void setMobilephone(String mobilephone) {
        this.mobilephone = mobilephone;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public long getUap_uid() {
        return uap_uid;
    }

    public long getNDUap_uid() { // 网龙版返回 Oap_uid
        return uid;
    }

    public void setUap_uid(long uap_uid) {
        this.uap_uid = uap_uid;
    }
    public void setUap_uid(int uap_uid) {
        this.uap_uid = uap_uid;
    }

    public String getNickname() {
        return nickname;
    }

    public void setNickname(String nickname) {
        this.nickname = nickname;
    }

    public String getJoindate() {
        return joindate;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    public String getBirthday() {
        return birthday;
    }

    public void setBirthday(String birthday) {
        this.birthday = birthday;
    }

    public String getBlood() {
        return blood;
    }

    public void setBlood(String blood) {
        this.blood = blood;
    }

    public String getSite() {
        return site;
    }

    public int getIsgetall() {
        return isgetall;
    }

    public void setIsgetall(int isgetall) {
        this.isgetall = isgetall;
    }

    public int getUnittype() {
        return unittype;
    }

    public void setUnittype(int unittype) {
        this.unittype = unittype;
    }

    public void setSite(String site) {
        this.site = site;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getFax() {
        return fax;
    }

    public void setFax(String fax) {
        this.fax = fax;
    }

    public String getAddr() {
        return addr;
    }

    public void setAddr(String addr) {
        this.addr = addr;
    }

    public String getPostcode() {
        return postcode;
    }

    public void setPostcode(String postcode) {
        this.postcode = postcode;
    }

    public void setJoindate(String joindate) {
        this.joindate = joindate;
    }

    public String getTelephone() {
        return telephone;
    }

    public void setTelephone(String telephone) {
        this.telephone = telephone;
    }

    public String getSignature() {
        return signature;
    }

    public void setSignature(String signature) {
        this.signature = signature;
    }

    public long getUpdatetime() {
        return updatetime;
    }

    public void setUpdatetime(long updatetime) {
        this.updatetime = updatetime;
    }

    public int getIsactive() {
        return isactive;
    }

    public void setIsactive(int isactive) {
        this.isactive = isactive;
    }

    public int getSysavatar() {
        return sysavatar;
    }

    public void setSysavatar(int sysavatar) {
        this.sysavatar = sysavatar;
    }

    /*
     * 家长时，unitid=0
     */
    public int getUnitid() {
        if (unitid == 0 && ApplicationVariable.INSTANCE.getCurrentUserInfo() != null) {
            unitid = ApplicationVariable.INSTANCE.getCurrentUserInfo().getOapUnitId();
        }
        return unitid;
    }

    public void setUnitid(int unitid) {
        this.unitid = unitid;
    }

    public String getUnitname() {
        return unitname;
    }

    public void setUnitname(String unitname) {
        this.unitname = unitname;
    }

    public long getUid() {
        return uid;
    }

    public void setUid(long uid) {
        this.uid = uid;
    }

    public long getFriend_updatetime() {
        return friend_updatetime;
    }

    public void setFriend_updatetime(long friendUpdatetime) {
        friend_updatetime = friendUpdatetime;
    }

    public int getIsadmin() {
        return isadmin;
    }

    public void setIsadmin(int isadmin) {
        this.isadmin = isadmin;
    }

    public int getIsgetextinfo() {
        return isgetextinfo;
    }

    public void setIsgetextinfo(int isgetextinfo) {
        this.isgetextinfo = isgetextinfo;
    }

    public int getReceivegroupmsg() {
        return receivegroupmsg;
    }

    public void setReceivegroupmsg(int receivegroupmsg) {
        this.receivegroupmsg = receivegroupmsg;
    }

    public int getDeporcassid() {
        return deporcassid;
    }

    public void setDeporcassid(int deporcassid) {
        this.deporcassid = deporcassid;
    }

    public String getAge() {
        return TimeUtils.getAgeByBirthday(birthday);
    }

    public void updateUser(BindUser user) {
        this.uid = user.getUid();
        this.uap_uid = user.getUap_uid();
        this.nickname = user.getNickname();
        this.joindate = user.getJoindate();
        this.gender = user.gender;
        this.telephone = user.getTelephone();
        this.signature = user.getSignature();
        this.updatetime = user.getUpdatetime();
        this.isactive = user.getIsactive();
        this.sysavatar = user.getSysavatar();
        this.username = user.getUsername();
        this.type = user.getType();
        this.workid = user.getWorkid();
        this.duty = user.getDuty();
        this.mobilephone = user.getMobilephone();
        this.birthday = user.getBirthday();
        this.email = user.getEmail();
        this.unitid = user.getUnitid();
        if (this.type != PARENT) {
            this.unitname = user.getUnitname();
        }
        this.studentid = user.getStudentid();
    }

    /*
     * 设置用户扩展资料
     */
    public void setJsonObject(JSONObject json) {
        this.gender = JSONUtils.getString(json, "gender");
        this.birthday = JSONUtils.getString(json, "birthday");
        this.blood = JSONUtils.getString(json, "blood");
        this.site = JSONUtils.getString(json, "site");
        this.description = JSONUtils.getString(json, "description");
        this.fax = JSONUtils.getString(json, "fax");
        this.addr = JSONUtils.getString(json, "addr");
        this.postcode = JSONUtils.getString(json, "postcode");
    }

    public void setJsonUpdatetime(JSONObject json) {
        this.updatetime = JSONUtils.getLong(json, "updatetime");
        this.friend_updatetime = JSONUtils.getLong(json, "friend_updatetime");
    }

    public boolean isTag() {
        return tag;
    }

    public void setTag(boolean tag) {
        this.tag = tag;
    }

    // public void save(){
    // if(uid==0||unitid==0) return;
    // DaoFactory.getInstance().getUserInfoDAO().updateUserInfo(this);
    // }

}
